<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: gpsExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('gpsExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">gpsExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example program to connect to a GPS and read and display data on the terminal. Also tries to connect to a TCM compass through the computer serial port, and use that to set the <a class="el" href="classArGPS.html" title="GPS Device Interface. ">ArGPS</a> compass data.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArGPS.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArGPSConnector.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArTrimbleGPS.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArTCMCompassDirect.h&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">  <a name="a0"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a1"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a2"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a name="_a3"></a><a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  <a name="_a4"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;parser, &amp;robot);</div><div class="line">  <a name="_a5"></a><a class="code" href="classArGPSConnector.html">ArGPSConnector</a> gpsConnector(&amp;parser);</div><div class="line"></div><div class="line">  <span class="comment">// Connect to the robot, get some initial data from it such as type and name,</span></div><div class="line">  <span class="comment">// and then load parameter files for this robot.</span></div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a6"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a name="a7"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a8"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gpsExample: Warning: Could not connect to robot.  Will not be able to switch GPS power on, or load GPS options from this robot&#39;s parameter file.&quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a9"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !parser.<a name="a10"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a name="a11"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gpsExample options:\n  -printTable   Print data to standard output in regular columns rather than a refreshing terminal display, and print more digits of precision&quot;</span>);</div><div class="line">    <a name="a12"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a13"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gpsExample: Connected to robot.&quot;</span>);</div><div class="line"></div><div class="line">  robot.<a name="a14"></a><a class="code" href="classArRobot.html#a3c3d878cfd11a2ef91230005a83bfcaa">runAsync</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <span class="comment">// check command line arguments for -printTable</span></div><div class="line">  <span class="keywordtype">bool</span> printTable = parser.<a name="a15"></a><a class="code" href="classArArgumentParser.html#a08d0d87154763e4869f0342a47059886">checkArgument</a>(<span class="stringliteral">&quot;printTable&quot;</span>);</div><div class="line"></div><div class="line">  <span class="comment">// On the Seekur, power to the GPS receiver is switched on by this command.</span></div><div class="line">  <span class="comment">// (A third argument of 0 would turn it off). On other robots this command is</span></div><div class="line">  <span class="comment">// ignored.</span></div><div class="line">  robot.<a name="a16"></a><a class="code" href="classArRobot.html#a37991669749d064691406e575b00564d">com2Bytes</a>(116, 6, 1);</div><div class="line"></div><div class="line">  <span class="comment">// Try connecting to a GPS. We pass the robot pointetr to the connector so it</span></div><div class="line">  <span class="comment">// can check the robot parameters for this robot type for default values for</span></div><div class="line">  <span class="comment">// GPS device connection information (receiver type, serial port, etc.)</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gpsExample: Connecting to GPS, it may take a few seconds...&quot;</span>);</div><div class="line">  <a name="_a17"></a><a class="code" href="classArGPS.html">ArGPS</a> *gps = gpsConnector.<a name="a18"></a><a class="code" href="classArGPSConnector.html#a4a58ea7f81bc75b8ddeea820ac541c48">createGPS</a>(&amp;robot);</div><div class="line">  <span class="keywordflow">if</span>(!gps || !gps-&gt;<a name="a19"></a><a class="code" href="classArGPS.html#a5edda03cc9e4c8db380e18f8d5465b7e">connect</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gpsExample: Error connecting to GPS device.  Try -gpsType, -gpsPort, and/or -gpsBaud command-line arguments. Use -help for help.&quot;</span>);</div><div class="line">    <span class="keywordflow">return</span> -1;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span>(gpsConnector.<a name="a20"></a>getGPSType() == <a name="a21"></a><a class="code" href="classArGPSConnector.html#ab7ddee30070f15cf1bcc8ec6cb4ca312adf049b3e1eec1403202c70dc1058fa88">ArGPSConnector::Simulator</a>)</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gpsExample: GPS data is from simulator.&quot;</span>);</div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">      If connected to MobileSim, and aa map is loaded into MobileSim that contains an OriginLatLonAlt line,</span></div><div class="line"><span class="comment">      then MobileSim will provides simulated GPS data based on the robot&#39;s </span></div><div class="line"><span class="comment">      true position in the simulator.  But you can also manually set &quot;dummy&quot;</span></div><div class="line"><span class="comment">      positions like this instead, or to simulate GPS without connecting</span></div><div class="line"><span class="comment">      to MobileSim:</span></div><div class="line"><span class="comment">    */</span></div><div class="line">    <span class="comment">//ArLog::log(ArLog::Normal, &quot;gpsExample: GPS is a simulator. Setting dummy position.&quot;);</span></div><div class="line">    <span class="comment">//(dynamic_cast&lt;ArSimulatedGPS*&gt;(gps))-&gt;setDummyPosition(42.80709, -71.579047, 100);</span></div><div class="line">  }</div><div class="line">  </div><div class="line"></div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gpsExample: Reading data...&quot;</span>);</div><div class="line">  <a name="_a22"></a><a class="code" href="classArTime.html">ArTime</a> lastReadTime;</div><div class="line">  <span class="keywordflow">if</span>(printTable)</div><div class="line">    gps-&gt;<a name="a23"></a>printDataLabelsHeader();</div><div class="line">  <span class="keywordflow">while</span>(<span class="keyword">true</span>)</div><div class="line">  {</div><div class="line">    <span class="keywordtype">int</span> r = gps-&gt;<a name="a24"></a><a class="code" href="classArGPS.html#ad503a2238efd4e8b447472ceacff6fe4">read</a>();</div><div class="line">    <span class="keywordflow">if</span>(r &amp; ArGPS::ReadError)</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gpsExample: Warning: error reading GPS data.&quot;</span>);</div><div class="line">      <a name="a25"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line">      <span class="keywordflow">continue</span>;</div><div class="line">    }</div><div class="line"></div><div class="line"></div><div class="line">    <span class="keywordflow">if</span>(r &amp; ArGPS::ReadUpdated)</div><div class="line">    {</div><div class="line">      <span class="keywordflow">if</span>(printTable)</div><div class="line">      {</div><div class="line">        gps-&gt;<a name="a26"></a><a class="code" href="classArGPS.html#abb87bcbe1297e2890a2eb51e999424f6">printData</a>(<span class="keyword">false</span>);</div><div class="line">        printf(<span class="stringliteral">&quot;\n&quot;</span>);</div><div class="line">      }</div><div class="line">      <span class="keywordflow">else</span></div><div class="line">      {</div><div class="line">        gps-&gt;<a class="code" href="classArGPS.html#abb87bcbe1297e2890a2eb51e999424f6">printData</a>();</div><div class="line">        printf(<span class="stringliteral">&quot;\r&quot;</span>);</div><div class="line">      }</div><div class="line">      fflush(stdout);</div><div class="line">      <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(500);</div><div class="line">      lastReadTime.<a name="a27"></a><a class="code" href="group__easy.html#ga7c269e161c8e7cb56bde73dea501a619">setToNow</a>();</div><div class="line">      <span class="keywordflow">continue</span>;</div><div class="line">    } <span class="keywordflow">else</span> {</div><div class="line">      <span class="keywordflow">if</span>(lastReadTime.<a name="a28"></a><a class="code" href="group__easy.html#ga5385636d566c665eb9d722af6f65aef5">secSince</a>() &gt;= 5) {</div><div class="line">        <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gpsExample: Warning: haven&#39;t recieved any data from GPS for more than 5 seconds!&quot;</span>);</div><div class="line">      }</div><div class="line">      <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line">      <span class="keywordflow">continue</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">  }</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
